package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.TagType;
import com.example.flshtarvel.mapper.TagTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;


@Service
public class TagTypeService {
    @Autowired(required = false)
    TagTypeMapper tagTypeMapperp;

    public TagType selectTagTypeById(String tagTypeId){
        return tagTypeMapperp.seleceTagTypeById(tagTypeId);
    }

    public TagType selectTagTypeByName(String tagTypeName){
        return tagTypeMapperp.selectTagTypeByName(tagTypeName);
    }

    public List<TagType> selectAllTagType(){
        return tagTypeMapperp.selectAllTagType();
    }

    public int insertTagType(TagType tagType){
        //检查标签类型是否已存在
        TagType tagTypeResult = tagTypeMapperp.selectTagTypeByName(tagType.getTagTypeName());
        if(tagTypeResult==null){
            tagType.setTagTypeId(UUID.randomUUID().toString());
            return tagTypeMapperp.inserTagType(tagType);
        }else{
            return 0;
        }
    }

}
